package com.example.zg.learn.enties;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

/**
 * 创建日期:2019/1/18 on 15:51
 * 描述：
 * 作者: zhougan
 */
public class Book  implements Parcelable{
    private String name;//书名
    private double price;//价格
    private Author author;//作者
    private List<Reader> readers;//读者
    private boolean isFinish;//是否完本
    private String[] tags;//标签


    public Book(String name, double price, Author author, boolean isFinish) {
        this.name = name;
        this.price = price;
        this.author = author;
        this.isFinish = isFinish;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public Author getAuthor() {
        return author;
    }

    public void setAuthor(Author author) {
        this.author = author;
    }

    public List<Reader> getReaders() {
        return readers;
    }

    public void setReaders(List<Reader> readers) {
        this.readers = readers;
    }

    public boolean isFinish() {
        return isFinish;
    }

    public void setFinish(boolean finish) {
        isFinish = finish;
    }

    public String[] getTags() {
        return tags;
    }

    public void setTags(String[] tags) {
        this.tags = tags;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    protected Book(Parcel in) {
        name = in.readString();
        price = in.readDouble();
        author = in.readParcelable(Author.class.getClassLoader());
        readers = in.createTypedArrayList(Reader.CREATOR);
        isFinish = in.readByte() != 0;
        tags = in.createStringArray();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeDouble(price);
        dest.writeParcelable(author, flags);
        dest.writeTypedList(readers);
        dest.writeByte((byte) (isFinish ? 1 : 0));
        dest.writeStringArray(tags);
    }

    public static final Creator<Book> CREATOR = new Creator<Book>() {
        @Override
        public Book createFromParcel(Parcel in) {
            return new Book(in);
        }

        @Override
        public Book[] newArray(int size) {
            return new Book[size];
        }
    };

}
